from django.db import models

class Category(models.Model):  #类别表
    id = models.AutoField(primary_key=True)  #id字段，自增列，主键
    name = models.CharField(max_length=50)  #名称，字符串，长度50
    order = models.IntegerField(default=0)  #排序字符，约定数字大的排前面
    image = models.CharField(max_length=100)  #封面图片，存文件路径


class Content(models.Model):  #内容表  文章/图片都是一种类型形式
    id = models.AutoField(primary_key=True)  #id字段，自增列，主键
    category = models.ForeignKey("Category", on_delete=models.CASCADE)  #类别表的外键
    title = models.CharField(max_length=200)  #标题
    text = models.CharField(max_length=100000)  #内容
    creation_time = models.DateTimeField()  #时间
    image = models.CharField(max_length=100)  #封面图片，存文件路径
    like = models.IntegerField(default=0)  #赞
    view_count = models.IntegerField(default=0)
    tag = models.CharField(max_length=100)
    comment_count = models.IntegerField(default=0)

    def tag_as_list(self):
        return self.tag.split(',')

class Comment(models.Model):  #评论
    id = models.AutoField(primary_key=True)  #id字段，自增列，主键
    content = models.ForeignKey("Content", on_delete=models.CASCADE)  #内容表的外键
    text = models.CharField(max_length=100000)  #内容
    creation_time = models.DateTimeField()  #时间
    like = models.IntegerField(default=0)  #赞
    nickname = models.CharField(max_length=50)  #评论人的昵称
    ip = models.CharField(max_length=100)   #评论人的IP地址

class User(models.Model):
    name = models.CharField(max_length=50,primary_key=True)
    password = models.CharField(max_length=50)